home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Peter Lewis / PNL Libraries / MyTriangleCDEF.p < prev    next >
Encoding:
Text File  |  1994-04-15  |  3.8 KB  |  159 lines  |  [TEXT/PJMM]

  1. unit MyTriangleCDEF;
  2.  
  3. interface
  4.  
  5.     function TriangleCDEF (variation: integer; theControl: ControlHandle; msg: integer; param: longInt): longInt;
  6.  
  7. implementation
  8.  
  9.     const
  10.         kInactive = 255;        {    part code indicating the control is inactive        }
  11.         inButton = inUpButton;
  12.  
  13.     function TriangleCDEF (variation: integer; theControl: ControlHandle; msg: integer; param: longInt): longInt;
  14.         procedure GetRgn (rgn: RgnHandle);
  15.             const
  16.                 offset = 2;
  17.                 offset2 = 2;
  18.             var
  19.                 r: Rect;        {    the rect to draw the PICT in    }
  20.                 pt: Point;
  21.                 siz: Point;
  22.                 value: integer;
  23.         begin
  24.             r := theControl^^.contrlRect;
  25.             value := theControl^^.contrlValue mod 8;
  26.             pt.h := (r.left + r.right) div 2;
  27.             pt.v := (r.top + r.bottom) div 2;
  28.             if odd(value) then begin
  29.                 siz.h := 3 * (r.right - r.left) div 4;
  30.                 siz.v := 3 * (r.bottom - r.top) div 4;
  31.             end
  32.             else begin
  33.                 siz.h := (r.right - r.left) div 2;
  34.                 siz.v := (r.bottom - r.top) div 2;
  35.             end;
  36.             OpenRgn;
  37.             case value of
  38.                 0:  begin
  39.                     MoveTo(pt.h, pt.v + offset - siz.v);
  40.                     Line(siz.h, siz.v);
  41.                     Line(-2 * siz.h, 0);
  42.                     Line(siz.h, -siz.v);
  43.                 end;
  44.                 1:  begin
  45.                     MoveTo(pt.h - offset2 + siz.h div 2, pt.v + offset2 + siz.v div 2);
  46.                     Line(0, -siz.v);
  47.                     Line(-siz.h, 0);
  48.                     Line(siz.h, siz.v);
  49.                 end;
  50.                 2:  begin
  51.                     MoveTo(pt.h - offset + siz.h, pt.v);
  52.                     Line(-siz.h, siz.v);
  53.                     Line(0, -2 * siz.v);
  54.                     Line(siz.h, siz.v);
  55.                 end;
  56.                 3:  begin
  57.                     MoveTo(pt.h - offset2 + siz.h div 2, pt.v - offset2 - siz.v div 2);
  58.                     Line(0, siz.v);
  59.                     Line(-siz.h, 0);
  60.                     Line(siz.h, -siz.v);
  61.                 end;
  62.                 4:  begin
  63.                     MoveTo(pt.h, pt.v - offset + siz.v);
  64.                     Line(siz.h, -siz.v);
  65.                     Line(-2 * siz.h, 0);
  66.                     Line(siz.h, siz.v);
  67.                 end;
  68.                 5:  begin
  69.                     MoveTo(pt.h + offset2 - siz.h div 2, pt.v - offset2 - siz.v div 2);
  70.                     Line(0, siz.v);
  71.                     Line(siz.h, 0);
  72.                     Line(-siz.h, -siz.v);
  73.                 end;
  74.                 6:  begin
  75.                     MoveTo(pt.h + offset - siz.h, pt.v);
  76.                     Line(siz.h, siz.v);
  77.                     Line(0, -2 * siz.v);
  78.                     Line(-siz.h, siz.v);
  79.                 end;
  80.                 7:  begin
  81.                     MoveTo(pt.h + offset2 - siz.h div 2, pt.v + offset2 + siz.v div 2);
  82.                     Line(0, -siz.v);
  83.                     Line(siz.h, 0);
  84.                     Line(-siz.h, siz.v);
  85.                 end;
  86.             end;
  87.             CloseRgn(rgn);
  88.         end;
  89.  
  90.         var
  91.             result: longInt;        {    the result to return        }
  92.             hilite: integer;        {    the current control hilite state    }
  93.             rgn: RgnHandle;
  94.             mousePoint: Point;
  95.     begin
  96.         result := 0;
  97.  
  98.         case msg of
  99.             initCntl: 
  100.                 ; { We won't get this call anyway }
  101.  
  102.             drawCntl:  begin    {    Draw the arrow control                }
  103.                 if theControl^^.contrlVis <> 0 then begin
  104.                     rgn := NewRgn;
  105.                     GetRgn(rgn);
  106.                     EraseRect(theControl^^.contrlRect);
  107.                     case theControl^^.contrlHilite of
  108.                         kInactive:  begin
  109.                             PenPat(gray);
  110.                             FrameRgn(rgn);
  111.                             PenPat(black);
  112.                         end;
  113.                         0, inButton:  begin
  114.                             if (theControl^^.contrlValue > 7) = (theControl^^.contrlHilite = inButton) then begin
  115.                                 FrameRgn(rgn);
  116.                             end
  117.                             else begin
  118.                                 FillRgn(rgn, black);
  119.                             end;
  120.                         end;
  121.                         otherwise
  122.                             ;
  123.                     end;
  124.                     DisposeRgn(rgn);
  125.                 end;
  126.             end;
  127.  
  128.             testCntl:  begin        {    Determine which part of the arrow the mouse is in    }
  129.                 mousePoint.v := hiwrd(param);
  130.                 mousePoint.h := lowrd(param);
  131.  
  132.             {    If the mouse point is in the control and it is active, determine which part the mouse went down in.            }
  133.                 if (theControl^^.contrlHilite <> kInactive) then{ & PtInRect(mousePoint, theControl^^.contrlRect) }
  134.                     begin
  135.                     rgn := NewRgn;
  136.                     GetRgn(rgn);
  137.                     if PtInRgn(mousePoint, rgn) then begin
  138.                         result := inButton;
  139.                     end;
  140.                     DisposeRgn(rgn);
  141.                 end;
  142.             end;
  143.  
  144.             calcCRgns, calcCntlRgn, calcThumbRgn:  begin
  145.                 param := longInt(StripAddress(Ptr(param)));        { Mask off the high byte if necessary }
  146.                 GetRgn(RgnHandle(param));
  147.             end;
  148.  
  149.             dispCntl: 
  150.                 ;
  151.  
  152.             otherwise
  153.                 ;
  154.         end;
  155.  
  156.         TriangleCDEF := result;
  157.     end;
  158.  
  159. end.